//
//  LPPHelpController.m
//  Lottery
//
//  Created by 刘盼 on 16/1/22.
//  Copyright © 2016年 lhheh. All rights reserved.
//

#import "LPPHelpController.h"
#import "LPPHelpModel.h"
#import "LPPHelpCellController.h"
@interface LPPHelpController ()

@property(nonatomic,strong)NSArray *helps;
@end

@implementation LPPHelpController
//加载数据
-(NSArray *)helps{
    
    if (!_helps) {
        
        NSString *path = [[NSBundle mainBundle]pathForResource:@"help" ofType:@"json"];
        
        NSData *data = [NSData dataWithContentsOfFile:path];
        //解析
        NSArray *tempArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:NULL];
        
        NSMutableArray *array = [NSMutableArray array];
        
        for (NSDictionary *dict in tempArray) {
          
            LPPHelpModel *model = [LPPHelpModel helpModelWithDictionary:dict];
            
            [array addObject:model];
        }
        _helps = array;
    }
    return _helps;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

#pragma mark---------<UITableViewDataSource>---------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.helps.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *helpId = @"help";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:helpId];
    
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:helpId];
    }
    LPPHelpModel *model = self.helps[indexPath.row];
    
    cell.textLabel.text = model.title;
    
    cell.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow_right"]];
    
    return cell;
}
#pragma mark--------<UITableViewDelegate>------------
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LPPHelpCellController *helpCell = [[LPPHelpCellController alloc]init];
    
    helpCell.model = self.helps[indexPath.row];
    
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:helpCell];
    /**
     UIModalTransitionStyleCoverVertical  从下往上出现视图
     UIModalTransitionStyleFlipHorizontal  左右翻转效果
     UIModalTransitionStyleCrossDissolve,  渐变效果
     UIModalTransitionStylePartialCurl     翻页效果
     */
    //modal视图的方式
    helpCell.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    
    /**
     UIModalPresentationFullScreen
     UIModalPresentationPageSheet
     UIModalPresentationFormSheet
     UIModalPresentationCurrentContext
     UIModalPresentationCustom
     UIModalPresentationOverFullScreen
     UIModalPresentationOverCurrentContext
     UIModalPresentationPopover
     UIModalPresentationNone
     */
//    helpCell.modalPresentationStyle = UIModalPresentationPopover;
    
    [self presentViewController:nav animated:YES completion:nil];
}
@end
